package com.train.member.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import com.train.common.until.MemberLoginContextUtil;
import com.train.common.until.SnowUtil;
import com.train.member.domain.Passenger;
import com.train.member.mapper.PassengerMapper;
import com.train.member.req.PassengerSaveReq;
import com.train.member.service.PassageService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class PassageServerImpl implements PassageService {
    @Resource
    private PassengerMapper passengerMapper;

    @Override
    public void savePassage(PassengerSaveReq passengerSaveReq) {
        long id = SnowUtil.getSnowflakeNextId();
        DateTime now = DateTime.now();
        passengerSaveReq.setId(id);
        System.out.println("会员id是"+MemberLoginContextUtil.getId());
        passengerSaveReq.setMemberId(MemberLoginContextUtil.getId());
        passengerSaveReq.setCreateTime(now);
        passengerSaveReq.setUpdateTime(now);

        Passenger passenger = BeanUtil.copyProperties(passengerSaveReq, Passenger.class);
        passengerMapper.insert(passenger);
    }
}
